local wumei = fk.CreateSkill({
  name = "pc__wumei",
  tags = {Skill.Compulsory},
})

wumei:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player == target and player:hasSkill(wumei.name) and not player:insideExtraTurn() and
    #player.room.logic:getActualDamageEvents(1, function(e)
        return e.data.from == player
      end, Player.HistoryTurn) == 0 and
    #player.room.logic:getActualDamageEvents(1, function(e)
        return e.data.to == player
      end, Player.HistoryTurn) == 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player:getMark("@pc__wumei-round")<4 and player:getMark("@pc__wumei-round")>0 then
        room:askToGuanxing(player, { cards = room:getNCards(player:getMark("@pc__wumei-round"),"top"), skill_name = wumei.name})
    elseif player:getMark("@pc__wumei-round")>0 then
        room:askToGuanxing(player, { cards = room:getNCards(4), skill_name = wumei.name})
    end
    
    local targets = table.filter(player.room.alive_players, function(id)
        return #id:getCardIds("h") == #player:getCardIds("h")
    end)
    local actor = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "寤寐：令一名手牌数等于你的角色执行一个额外回合",
      skill_name = wumei.name,
      cancelable = false
    })
    if not actor[1].dead then
      actor[1]:gainAnExtraTurn(true, wumei.name)
    end
  end,
})

wumei:addEffect(fk.FinishJudge, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(wumei.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@pc__wumei-round")
  end,
})

Fk:loadTranslationTable {
["pc__wumei"] = "寤寐",
[":pc__wumei"] = "<b>锁定技</b>，额定回合结束时，若你本回合未造成且未受到过伤害，你卜算X，然后令一名手牌数等于你的角色执行一个额外回合（X为你本轮判定过的次数且至多为4）。",
["$pc__wumei1"] = "",
["$pc__wumei2"] = "",
["@pc__wumei-round"] = "寤寐",
}
return wumei